home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / polar_contour.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  109 lines

  1. ; $Id: polar_contour.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1995-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO Polar_Contour, z, theta, r, SHOW_TRIANGULATION=show, _Extra = e
  7. ;
  8. ; Copyright (c) 1995, Research Systems, Inc.  All rights reserved.
  9. ;    Unauthorized reproduction prohibited.
  10. ;+
  11. ; NAME:
  12. ;    POLAR_CONTOUR
  13. ;
  14. ; PURPOSE:
  15. ;    Produce a contour plot from data in polar coordinates.
  16. ;    Data may be in a regular or scattered grid.
  17. ; CATEGORY:
  18. ;    Graphics.
  19. ;
  20. ; CALLING SEQUENCE:
  21. ;    POLAR_CONTOUR, Z, Theta, R
  22. ; INPUTS:
  23. ;    Z = data values.  If regulary gridded, Z must have dimensions of 
  24. ;        (NTheta, NR).
  25. ;    Theta = values of theta in radians.  For the regular grid, Theta
  26. ;        must have the same number of elements as the first dimension
  27. ;        of Z.  For the scattered grid, Theta must have the same number
  28. ;        of elements as Z.
  29. ;    R = values of radius.  For the regular grid, R
  30. ;        must have the same number of elements as the second dimension
  31. ;        of Z.  For the scattered grid, R must have the same number
  32. ;        of elements as Z.
  33. ; KEYWORD PARAMETERS:
  34. ;    SHOW_TRIANGULATION = color.  If set, the triangulation connecting
  35. ;        the data points is overplotted in the designated color.
  36. ;
  37. ;    Also, most of the keywords accepted by CONTOUR may be specified.
  38. ;    Keywords associated with contour following, such as FOLLOW,
  39. ;    PATH_xxx, and C_LABELS, are not accepted.
  40.  
  41. ; OUTPUTS:
  42. ;    A contour plot is produced.
  43. ; COMMON BLOCKS:
  44. ;    None.
  45. ; SIDE EFFECTS:
  46. ;    Plot is produced on the current graphics output device.
  47. ; RESTRICTIONS:
  48. ;    None.
  49. ; PROCEDURE:
  50. ;    The cartesian coordinates of each point are calculated.
  51. ;    TRIANGULATE is called to grid the data into triangles.
  52. ;    CONTOUR is called to produce the contours from the triangles.
  53. ; EXAMPLE:
  54. ;        Example with regular grid:
  55. ;    nr = 12        ;# of radii
  56. ;    nt = 18        ;# of thetas
  57. ;    r = findgen(nr) / (nr-1)   ;Form r and Theta vectors
  58. ;    theta = 2 * !pi * findgen(nt) / (nt-1)
  59. ;    z = cos(theta*3) # (r-.5)^2   ;Fake function value
  60. ;    tek_color
  61. ;        Create filled contours:
  62. ;    Polar_Contour, z, theta, r, /fill, c_color=[2,3,4,5]
  63. ;
  64. ;        Example with random (scattered) grid:
  65. ;    n = 200
  66. ;    r = randomu(seed, n)        ;N random r's and Theta's
  67. ;    theta = 2*!pi * randomu(seed, n)
  68. ;    x = cos(theta) * r        ;Make a function to plot
  69. ;    y = sin(theta) * r
  70. ;    z = x^2 - 2*y
  71. ;    Polar_Contour, z, theta, r, Nlevels=10, xrange=[0,1], yrange=[0,1]
  72. ;
  73. ; MODIFICATION HISTORY:
  74. ;     Written by:    Your name here, Date.
  75. ;    January, 1995.    DMS, RSI.
  76. ;-
  77.  
  78. on_error, 2        ;Return to caller...
  79. s = size(z)
  80. nz = n_elements(z)
  81.  
  82. if (s[0] eq 2) and (n_elements(theta) eq s[1]) and $   ;Regular grid case?
  83.    (n_elements(r) eq s[2]) then begin
  84.   tt = theta # replicate(1,n_elements(r))
  85.   rr = replicate(1,n_elements(theta)) # r
  86.   x = rr * cos(tt)
  87.   y = rr * sin(tt)
  88. endif else begin        ;Irregular grid
  89.   if n_elements(r) ne nz then message, $
  90.     'R array has wrong number of elements'
  91.   if n_elements(theta) ne nz then message, $
  92.     'Theta array has wrong number of elements'
  93.   x = r * cos(theta)
  94.   y = r * sin(theta)
  95. endelse
  96.  
  97. triangulate, x, y, tr
  98. contour, z, x, y, TRIANGULATION=tr, _EXTRA=e
  99.  
  100. if n_elements(show) eq 1 then begin    ;Show the triangulation?
  101.     oplot, x, y, /psym, color=show
  102.     for i=0, n_elements(tr)/3-1 do begin
  103.       t = [tr[*,i], tr[0,i]]
  104.       plots, x[t], y[t], color=show
  105.       endfor
  106.     endif
  107. end
  108.  
  109.